import axios from 'axios';
import { message, Button } from 'antd';
import router from "umi/router"
import {_getcaptch}  from "../api/api"
import cookie from "react-cookies"
const httpAxios = axios.create();

httpAxios.interceptors.request.use(
  (config: any) => {
    // console.log(config, 565655);

    return {
      ...config,
      headers: {
        ...config.headers,
        Authorization: cookie.load('token') ? cookie.load('token'): '',
      },
    };
  },
  (error: any) => {
    return error;
  },
),
  httpAxios.interceptors.response.use(
    (response: any) => {
      // console.log(response, 'response');
      // message.info(response.data.msg);

      if (response.data.code == 401 ) {
        router.push('/login');
      }
      return response;
    },
    (error: any) => {
      return error;
    },
  );
export default httpAxios;
